package itheima.mocc.myreflect5;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Method2 {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
//        method1();
        Class clazz = Class.forName("itheima.mocc.myreflect5.Student");
        Method declaredMethod = clazz.getDeclaredMethod("show", int.class);
        declaredMethod.setAccessible(true);
        Student student= (Student) clazz.newInstance();
        Object invoke = declaredMethod.invoke(student, 33);
        System.out.println(invoke);
    }

    private static void method1() throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Class clazz = Class.forName("itheima.mocc.myreflect5.Student");
        Method method = clazz.getMethod("fun4", String.class);
        Student student = (Student) clazz.newInstance();
        Object result = method.invoke(student, "十年磨一剑");
        System.out.println(result);
    }
}
